﻿using Microsoft.AspNetCore.Mvc;
using SYSoft.Model;
using SYSoft.Model.Models.DeviceManage.Maintain;
using SYSoft.Services.MaintainManage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SYSoft.Controllers.MaintainManage
{
    public class WH_knowledgeController : BaseController
    {

        IWH_knowledgeServices wH_Knowledge;
        public WH_knowledgeController(IWH_knowledgeServices wH_Knowledge)
        {
            this.wH_Knowledge = wH_Knowledge;
        }



        /// <summary>
        /// 获取基础库所有知识
        /// </summary>
        /// <param name="devicename">2012-09-21</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MessageModel<PageModel<WH_knowledge>>> GetAllList(int page = 1, int size = 10)
        {

            var model = await wH_Knowledge.QueryPage(null, page, size);
            if (model.data != null && model.data.Count > 0)
            {
                return MessageModel.CreateSuccessResult(model);
            }
            return MessageModel.CreateFailedResult<PageModel<WH_knowledge>>("");
        }



        /// <summary>
        /// 获取基础库所有知识
        /// </summary>
        /// <param name="devicename">2012-09-21</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageModel<List<WH_knowledge>>> GetListByField(string devicename,string str)
        {

            var model = await wH_Knowledge.listSelect(devicename,str);
            if (model != null && model.Count > 0)
            {
                return MessageModel.CreateSuccessResult(model);
            }
            return MessageModel.CreateFailedResult<List<WH_knowledge>>("");
        }



        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<MessageModel<int>> Post([FromBody] WH_knowledge model)
        {
            var res = await wH_Knowledge.Add(model);
            if (res > 0)
                return MessageModel.CreateSuccessResult(res);
            else
                return MessageModel.CreateFailedResult<int>("Id必须大于0");
        }



        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<MessageModel<string>> Update([FromBody] WH_knowledge model)
        {

            //sysUserInfo.UpdateBy = Operator.UserId; //操作者
            var res = await wH_Knowledge.Update(model);
            if (res)
                return MessageModel.CreateSuccessResult<string>("sucess");
            return MessageModel.CreateFailedResult<string>("修改任务信息失败！！");
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<MessageModel<string>> Delete(int id)
        {
            if (id > 0)
            {
                var userDetail = await wH_Knowledge.QueryById(id);
                bool res = await wH_Knowledge.Delete(userDetail);
                if (!res)
                    return MessageModel.CreateFailedResult<string>("删除任务失败！！");
                return MessageModel.CreateSuccessResult("删除任务成功");
            }
            return MessageModel.CreateFailedResult<string>("Id必须大于0");
        }

    }
}
